<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\Models\Category;

class CreateCategoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('parent_id')->default(0)->comment('上级');
            $table->string('title', 20)->default()->comment('类型名称');
            $table->text('description')->nullable()->comment('描述');
            $table->unsignedInteger('sort')->default(0)->comment('排序');
            $table->timestamps();
        });

        $now = Carbon\Carbon::now();
        Category::insert([
            ['parent_id' => 0, 'title' => '图片','description' =>'站点公告', 'created_at' => $now, 'updated_at' => $now],
            ['parent_id' => 0, 'title' => '视频','description' =>'分享创造，分享发现', 'created_at' => $now, 'updated_at' => $now],
            ['parent_id' => 1, 'title' => '动漫','description' =>'开发技巧、推荐扩展包等', 'created_at' => $now, 'updated_at' => $now],
            ['parent_id' => 1, 'title' => '美女','description' =>'请保持友善，互帮互助', 'created_at' => $now, 'updated_at' => $now],
            ['parent_id' => 2, 'title' => '电影','description' =>'欧美电影大片', 'created_at' => $now, 'updated_at' => $now],
            ['parent_id' => 2, 'title' => '电视剧','description' =>'爱情电视剧', 'created_at' => $now, 'updated_at' => $now],
        ]);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('categories');
    }
}
